<script setup lang="ts">
import { RouterView } from "vue-router";
import { useAppStoreWithOut } from "@/store/modules/app";
import { onMounted } from "vue";
import { useRouter } from "vue-router";
import { getStorage } from "@/utils/storage/storage";
import { isEmpData, useCopyCode } from "@/utils";
import { getUsetInfo } from "./api/user-app";
import { userInfo } from "./types/app";

const router = useRouter();
const appstore = useAppStoreWithOut();
useCopyCode()
onMounted(async () => {
  const token: string = getStorage("token");
  if (!isEmpData(token) && token != '') {
  try {
      appstore.setToken(token);
     
    const res = await getUsetInfo<userInfo>()
    appstore.setUserInfo(res)
  } catch (error) {
     router.push("/login");
  }
  } else {
    router.push("/login");
  }
});
</script>

<template>
  <RouterView />
</template>

<style scoped lang="scss"></style>
